package strongholdCraft.common.Items.tool;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.UseHoeEvent;

public class ItemSmelter extends Item {
	public ItemSmelter(int id){
		super(id);
		setUnlocalizedName("Smelter");
		setMaxDamage(251);
		setMaxStackSize(1);
	}
	
	int[] smeltableBlocks =
		{
			Block.oreIron.blockID, Block.oreGold.blockID, Block.oreDiamond.blockID, Block.cactus.blockID,
			Block.wood.blockID, Block.oreEmerald.blockID, Block.netherrack.blockID, Block.oreCoal.blockID,
			Block.oreRedstoneGlowing.blockID, Block.oreLapis.blockID, Block.oreNetherQuartz.blockID
		};
	
	ItemStack[] smeltedItems = 
		{
			new ItemStack(Item.ingotIron), new ItemStack(Item.ingotGold), new ItemStack(Item.diamond),
			new ItemStack(Item.dyePowder, 1, 2), new ItemStack(Item.coal, 1, 1), new ItemStack(Item.emerald), 
			new ItemStack(Item.netherrackBrick), new ItemStack(Item.coal), new ItemStack(Item.redstone), 
			new ItemStack(Item.dyePowder, 1, 4), new ItemStack(Item.netherQuartz)
		};
	
	
	public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6,
			int par7, float par8, float par9, float par10){
		
		if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)){
			return false;
		}
		else{
			UseHoeEvent event = new UseHoeEvent(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6);
			if (MinecraftForge.EVENT_BUS.post(event)){
				return false;
				}
			
			if (event.getResult() == Result.ALLOW){
				par1ItemStack.damageItem(1, par2EntityPlayer);
				return true;
				}
			
			int var11 = par3World.getBlockId(par4, par5, par6);
			int var12 = par3World.getBlockId(par4, par5 + 1, par6);
			
			
					int i = 0;
					if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
						i++;
						if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
							i++;
							if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
								i++;
								if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
									i++;
									if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
										i++;
										if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
											i++;
											if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
												i++;
												if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
													i++;
													if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
														i++;
														if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
															i++;
															if ((par7 == 0 || var12 != 0 || var11 != smeltableBlocks[i])){
																i++;
																if ((par7 == 0 || var12 != 0 || var11 != Block.sand.blockID)){
																	if ((par7 == 0 || var12 != 0 || var11 != Block.cobblestone.blockID)){
																		return false;
																		}
																	else{
																		if (par3World.isRemote){return true;}
																		else{		//"x,y,z,id,meta"
																			par3World.setBlock(par4, par5, par6, 1, 1, 0x02);
																			par1ItemStack.damageItem(1, par2EntityPlayer);
																			return true;
																		}
																	}
																	}
																else{
																	if (par3World.isRemote){return true;}
																	else{		//"x,y,z,id,meta"
																		par3World.setBlock(par4, par5, par6, 20, 1, 0x02);
																		par1ItemStack.damageItem(1, par2EntityPlayer);
																		return true;
																	}
																}
																}
															else{
																if (par3World.isRemote){return true;}
																else{		//"x,y,z,id,meta"
																	par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
																	par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
																	par1ItemStack.damageItem(1, par2EntityPlayer);
																	return true;
																}
															}
															}
														else{
															if (par3World.isRemote){return true;}
															else{		//"x,y,z,id,meta"
																par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
																par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
																par1ItemStack.damageItem(1, par2EntityPlayer);
																return true;
															}
														}
														}
													else{
														if (par3World.isRemote){return true;}
														else{		//"x,y,z,id,meta"
															par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
															par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
															par1ItemStack.damageItem(1, par2EntityPlayer);
															return true;
														}
													}
													}
												else{
													if (par3World.isRemote){return true;}
													else{		//"x,y,z,id,meta"
														par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
														par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
														par1ItemStack.damageItem(1, par2EntityPlayer);
														return true;
													}
												}
												}
											else{
												if (par3World.isRemote){return true;}
												else{		//"x,y,z,id,meta"
													par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
													par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
													par1ItemStack.damageItem(1, par2EntityPlayer);
													return true;
												}
											}
											}
										else{
											if (par3World.isRemote){return true;}
											else{		//"x,y,z,id,meta"
												par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
												par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
												par1ItemStack.damageItem(1, par2EntityPlayer);
												return true;
											}
										}
										}
									else{
										if (par3World.isRemote){return true;}
										else{		//"x,y,z,id,meta"
											par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
											par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
											par1ItemStack.damageItem(1, par2EntityPlayer);
											return true;
										}
									}
									}
								else{
									if (par3World.isRemote){return true;}
									else{		//"x,y,z,id,meta"
										par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
										par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
										par1ItemStack.damageItem(1, par2EntityPlayer);
										return true;
									}
								}
								}
							else{
								if (par3World.isRemote){return true;}
								else{		//"x,y,z,id,meta"
									par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
									par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
									par1ItemStack.damageItem(1, par2EntityPlayer);
									return true;
								}
							}
							}
						else{
							if (par3World.isRemote){return true;}
							else{		//"x,y,z,id,meta"
								par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
								par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
								par1ItemStack.damageItem(1, par2EntityPlayer);
								return true;
							}
						}
						}
					else{
						if (par3World.isRemote){return true;}
						else{		//"x,y,z,id,meta"
							par3World.setBlock(par4, par5, par6, 0, 1, 0x02);
							par2EntityPlayer.dropPlayerItem(smeltedItems[i]);
							par1ItemStack.damageItem(1, par2EntityPlayer);
							return true;
						}
					}
			
		}
	
	}
}
